package adapter.role
{
	import datapool.global.GlobalInfo;
	import datapool.define.ActionDefine;
	import datapool.event.EventObject;
	import flash.geom.Point;
	import adapter.common.AdapterBase;

	/**
	 * @author Administrator
	 */
	public class MainRoleAdapter extends RoleAdapterBase
	{
		public function MainRoleAdapter(modelId : uint)
		{
			super(modelId);
		}
		
		override public function onFrame():void
		{
			super.onFrame();
			
			if(targetPostion && targetPostion.equals(new Point(absPostionX, absPostionY)))
			{
				return;
			}
			
			var eventObj:EventObject;
			if (_action == ActionDefine.ACTION_Z_L)
			{
				eventObj = new EventObject(EventObject.EVENT_PLAYER_POSTION_UPDATE);
				eventObj.param = new Point(absPostionX, absPostionY);
				context.eventMgr.dispatchEvent(eventObj);
			}
			
			if (_targetPos && _action == ActionDefine.ACTION_Z_L)
			{
				if ((Math.abs(_targetPos.x - roleUI.x - GlobalInfo.oppositePosX) <= speed) && 
				    (Math.abs(_targetPos.y - roleUI.y - GlobalInfo.oppositePosY) <=speed ))
				{
					onMoveComplete();
				}
			}
		}
		
		public function onMoveComplete():void
		{
			action = ActionDefine.ACTION_D_J;
		}
		
		override public function get isMainRole():Boolean
		{
			return true;
		}
	}
}
